package com.al.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;

@WebFilter(filterName="testFilter",urlPatterns="/*",initParams= {@WebInitParam(name="username",value="xiaomiao")})
public class TestFilter implements Filter {
	@Override
	public void doFilter(ServletRequest req, ServletResponse rep, FilterChain chain)
			throws IOException, ServletException {
		System.out.println("过滤中.....");
		//设置字符编码
		//req.setCharacterEncoding("UTF-8");   //写到了专门的字符编码过滤器中
		//千万不能忘掉这一步
		chain.doFilter(req, rep);
	}
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		String name = filterConfig.getInitParameter("username");
		System.out.println(name);
		System.out.println("filter 实例被建立");
	}
	@Override
	public void destroy() {
		System.out.println("==销毁==");
	}
}
